import {createSlice} from '@reduxjs/toolkit'

const counterStore = createSlice({
  name:'counter',
  //初始化state
  initialState:{
    count:0,
  },
  //修改状态的方法 同步方法 支持直接修改
  reducers:{
    increment(state){
      state.count++
    },
    decrement(state){
      state.count--
    },
    addToNum(state,action){
      console.log(state);
      console.log(action);
      state.count = action.payload
    }
  }
})
console.log('ccc',counterStore);
//解构出来actionCreater函数
const {increment,decrement,addToNum} = counterStore.actions
//获取reducer
const reducer = counterStore.reducer

// 以按需导出的方式到处actionCreater
export {increment,decrement,addToNum}
// 以默认导出的方式到处reducer
export default reducer
